﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Upsam.RopaOnline.Modelo.Common;

namespace Upsam.RopaOnline.Web
{
    public partial class PayTypeManagement : System.Web.UI.Page
    {
        private const string PAGE_NAME = "PayTypeManagement.aspx";
        private const string SEARCH_PAGE_NAME = "PayTypeSearch.aspx";

        protected void Page_Load(object sender, EventArgs e)
        {
            ConfigPageMode();
        }

        protected void fvwOrder_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
            if (e.CommandName.Equals(ConstantsEnums.CancelCommand))
                Response.Redirect(SEARCH_PAGE_NAME, false);
        }

        private void ConfigPageMode()
        {
            string pageMode = Request.QueryString[ConstantsEnums.QueryStringKeyPageMode];
            if (!string.IsNullOrEmpty(pageMode))
            {
                PageMode pageModeEnum = (PageMode)Enum.Parse(typeof(PageMode), pageMode, true);
                switch (pageModeEnum)
                {
                    case PageMode.EditMode:
                        fvwContext.ChangeMode(FormViewMode.Edit);
                        break;
                    case PageMode.InsertMode:
                        fvwContext.ChangeMode(FormViewMode.Insert);
                        break;
                    default:
                        fvwContext.ChangeMode(FormViewMode.ReadOnly);
                        break;
                }
            }
        }

        protected void fvwOrder_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
        {
            Response.Redirect(SEARCH_PAGE_NAME, false);
        }

        protected void fvwOrder_ItemInserted(object sender, FormViewInsertedEventArgs e)
        {
            Response.Redirect(SEARCH_PAGE_NAME, false);
        }
    }
}
